<?php
    //echo " Welcome to SK..!!!!"."</br>";
    

    
    
    research_papers($course_selected);
    
    function research_papers( $course_selected ){
        
        
        $link= array();
        $page=0;
        $count=0;
        while($count < 3){
        
            //$sourcelink = "http://ieeexplore.ieee.org/search/searchresult.jsp?newsearch=true&queryText=".$course_selected."&x=0&y=0";
            
    $sourcelink = "http://scholar.google.com/scholar?start=".$page."&q=".$course_selected."&btnG=&hl=en&as_sdt=0%2C5" ;
    
    //echo $sourcelink."</br>";
 
        
    @$html = file_get_contents($sourcelink);
    $dom_object = new DOMDocument();
    @$dom_object->loadHTML($html);
    $xpath_node = new DOMXPath($dom_object);
    
    //$hrefs_links = $xpath_node->evaluate("/html/body//a[b='java']");
    
        
    $a_tag = $xpath_node->query("/html/body//a");
    foreach ( $a_tag as $tag){
        
        $tag_value = $tag->nodeValue ;

        //echo $tag_value."</br>";
        
        $course= "|\b$course_selected\b|i";
        
        if(preg_match($course,$tag_value)) {
            
            $url = $tag->getAttribute('href');
            
            //echo $url;
            $acm = strpos($url,'acm');
            $ieee = strpos($url,'ieee');
            
            if ($acm==false && $ieee==false){
                $i=0;
            }
            else{
                //echo $url."</br>";
                $link[]=$url;
                preg_match( '@^(?:http://)?([^/]+)@i', $url, $matches );
                $host = $matches[1];
                preg_match('/[^.]+\.[^.]+$/', $host, $matches);
                $domain = $matches[0];
                //echo "domain :".$domain."</br>";
                
                $type = "papers";
                insertIntoDatabase($course_selected,$url,$domain,$type);
                
            }

            
        }
    }

            $count = count($link);
            $page=$page+10;
            
            if($page ==50){
                $count = 4;
            }
        
        }
    
    }
    
    
    


    

    
    
    
    
?>
        

